package com.example.secudemo.secu;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyUserDetailService implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        List<GrantedAuthority> list;
        if(username.equals("zhangsan")){
            list = AuthorityUtils.createAuthorityList("/product/add","/product/delete","ROLE_ADMIN");
        }else {
            list = AuthorityUtils.createAuthorityList("/product/update","/product/findAll","ROLE_USER");

        }
        User user = new User(username,"123",list);
        return user;
    }
}
